package com.beici.vueblogapp.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.StringVendorExtension;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Collection;

@Configuration
//开启Swagger
@EnableSwagger2
public class swaggerConfig {


    @Value("${spring.profiles.active}")
    private String environment;

    @Bean
    public Docket docket(){
        boolean flag = false;
        //判断当前是否为开发环境
        if (environment.equals("dev")){
            flag = true;
        }

        return new Docket(DocumentationType.SWAGGER_2)
                    //开启swagger
                    .enable(flag)
                    .apiInfo(getApiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("com.beici.vueblogapp.controller") )
                    .build()
                ;
    }
//    配置信息
    private ApiInfo getApiInfo(){
        /*
            String title,
             String description,
              String version,
               String termsOfServiceUrl,
                Contact contact,
                 String license,
                 String licenseUrl,
                  Collection< VendorExtension > vendorExtensions
         */
        Contact contact = new Contact("北辞",null,"746381864@qq.com");
        Collection<VendorExtension> collection = new ArrayList<>();
        collection.add(new StringVendorExtension("北辞","17"));
        return  new ApiInfo(
                "文章接口提供",
                "接口正常",
                "1.0",
                "http://localhost:8080",
                contact,
                null,
                null,
                collection
        );
    }
}
